import StudentDb from '../Model/Student.js'

let fn_List = async ctx => {
  ctx.body = await StudentDb.findAll()
}

let fn_GetOneData = async ctx => {
  ctx.body = await StudentDb.findByPk(ctx.request.params.id)
}

let fn_Add = async ctx => {
  await StudentDb.create(ctx.request.body)
  ctx.body = '添加成功'
}

let fn_Update = async ctx => {
  await StudentDb.update(ctx.request.body,{where : {id : ctx.request.params.id}})
  ctx.body = '修改成功'
}

let fn_Delete = async ctx => {
  await StudentDb.destroy({where : {id : ctx.request.params.id}})
  ctx.body = '删除成功'
}

export let obj = [
  {
    method : 'get',
    url : '/',
    fn : fn_List
  },
  {
    method : 'get',
    url : '/:id',
    fn : fn_GetOneData
  },
  {
    method : 'post',
    url : '/',
    fn : fn_Add
  },
  {
    method : 'put',
    url : '/:id',
    fn : fn_Update
  },  
  {
    method : 'delete',
    url : '/:id',
    fn : fn_Delete
  },
]